<template>
  <div>
    <el-dialog
      :title="title"
      :visible="dialogVisible"
      :show-close="false"
      width="650px"
    >
      <el-form
        ref="vehicleDialog"
        :rules="rules"
        :model="row"
        label-width="120px"
        style="margin-left: 30px;"
        :disabled="row.state === 1"
      >
        <el-form-item label="车辆品牌:" prop="cartype0" style="width: 350px">
          <el-select
            v-model="row.cartype0"
            placeholder="请选择"
            clearable
          >
            <el-option
              v-for="item in CarNameList()"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="车辆类型:" prop="cartype1" style="width: 350px">
          <el-select
            v-model="row.cartype1"
            placeholder="请选择"
            clearable
          >
            <el-option
              v-for="item in CarTypeList()"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="车牌号:" prop="num" style="width: 350px">
          <el-input
            v-model="row.num"
            size="medium"
            placeholder="请输入车牌号"
          />
        </el-form-item>
        <el-form-item label="颜色:" prop="color" style="width: 350px">
          <el-input
            v-model="row.color"
            size="medium"
            placeholder="请输入颜色"
          />
        </el-form-item>
        <el-form-item label="登记日期:" prop="regdate" style="width: 350px;">
          <el-date-picker
            v-model="row.regdate"
            type="date"
            size="medium"
            placeholder="请选择日期"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
          />
        </el-form-item>
        <el-form-item label="年审日期:" prop="yearcare" style="width: 350px;">
          <el-date-picker
            v-model="row.yearcare"
            type="date"
            size="medium"
            placeholder="请选择日期"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
          />
        </el-form-item>
        <el-form-item label="交强险日期:" prop="yearinsure0" style="width: 350px;">
          <el-date-picker
            v-model="row.yearinsure0"
            type="date"
            size="medium"
            placeholder="请选择日期"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
          />
        </el-form-item>
        <el-form-item label="商业险日期:" prop="yearinsure" style="width: 350px;">
          <el-date-picker
            v-model="row.yearinsure"
            type="date"
            size="medium"
            placeholder="请选择日期"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
          />
        </el-form-item>
        <el-form-item label="所在地区:" prop="city" style="width: 350px">
          <el-input
            v-model="row.city"
            size="medium"
            placeholder="请输入所在地区"
          />
        </el-form-item>
      </el-form>
      <span slot="footer">
        <el-button
          @click="handleCancel"
        >
          取 消
        </el-button>
        <el-button
          type="primary"
          @click="handleConfirm"
        >
          确 定
        </el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import mixin from '@/mixin/mixin'
export default {
  name: 'VehicleDialog',
  mixins: [mixin],
  props: {
    dialogVisible: {
      type: Boolean,
      default: false
    },
    row: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  data() {
    return {
      title: '',
      rules: {
        cartype0: [
          {
            required: true,
            message: '请选择车辆品牌',
            trigger: 'blur'
          }
        ],
        cartype1: [
          {
            required: true,
            message: '请选择车辆类型',
            trigger: 'blur'
          }
        ],
        num: [
          {
            required: true,
            message: '车牌号不能为空',
            trigger: 'blur'
          }
        ],
        color: [
          {
            required: true,
            message: '车辆颜色不能为空',
            trigger: 'blur'
          }
        ],
        city: [
          {
            required: true,
            message: '所在地区不能为空',
            trigger: 'blur'
          }
        ]
      }
    }
  },
  updated() {
    if (this.row.id) {
      this.title = '编辑信息'
    } else {
      this.title = '新增车辆'
    }
  },
  methods: {
    handleCancel() {
      this.$emit('cancel-dialog')
      this.$refs.vehicleDialog.resetFields()
    },
    handleConfirm() {
      this.$refs.vehicleDialog.validate((valid) => {
        if (valid) {
          this.$emit('confirm-dialog', {
            id: this.row.id,
            cartype0: this.row.cartype0,
            cartype1: this.row.cartype1,
            num: this.row.num,
            color: this.row.color,
            regdate: this.row.regdate,
            yearcare: this.row.yearcare,
            yearinsure0: this.row.yearinsure0,
            yearinsure: this.row.yearinsure,
            city: this.row.city
          })
        } else {
          return false
        }
      })
    }
  }
}
</script>

<style>
</style>
